package cn.zsb.zsb;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

public class Test {
    public static void main(String[] args) throws Exception {
//      写一个网址路径
        String url = "https://pan.hfbdqn.cn/showclist/5079.html";
        Document parse = Jsoup.parse(new URL(url), 10000);
        //  System.out.println(parse);
//        找图片的父元素id
//        Element content = parse.getElementById("");
        Elements content = parse.getElementsByClass("ML_ul");
        // System.out.println(content);
//        标签处理器
//        Elements imgs = content.getElementsByTag("a");
        for (Element element : content) {
            Elements a = element.getElementsByTag("a");
            for (Element m : a) {
                String href = m.attr("href");
                String secname = m.text();
                System.out.println("章节：" + secname+",网址："+href);

            }
        }
        //https://pan.hfbdqn.cn/Chapter/chapter.html?bookid=5079&num=4

//        System.out.println(imgs);
//        遍历集合找到所有的src
//        for (Element img : imgs) {
//            String src = img.attr("a");
////            System.out.println(src);
//            //获取输出流
//            URL target=new URL(src);
//            URLConnection urlConnection = target.openConnection();
//            InputStream inputStream = urlConnection.getInputStream();
//            //输出流
//            OutputStream outputStream=new FileOutputStream("D:\\pachong");//写本地地址
//            int temp=0;
//            while ( (temp=inputStream.read())!=-1 ){
//                outputStream.write(temp);
//            }
//            System.out.println("下载完毕");
//            outputStream.close();
//            inputStream.close();


    }
}
